package JZOffer;

/**
 * @author Lw中
 * @date 2021/8/9 22:40
 */
public class Jz28 {

    // Jz28.对称的二叉树

    public class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode(int x) { val = x; }
    }

    public boolean isSymmetric(TreeNode root) {
        // 使用递归的方法
        return root == null ? true : circleCompare(root.left, root.right);
    }

    private boolean circleCompare(TreeNode L, TreeNode R) {
        // 终止条件
        if (R == null && L == null) return true;
        else if (R == null || L == null || R.val != L.val) return false;
        else return circleCompare(L.left, R.right) && circleCompare(L.right, R.left);
    }

}
